package com.rykj.energy.database.service.impl;

import com.rykj.energy.database.mapper.UserConfigMapper;
import com.rykj.energy.database.pojo.BusinessUserConfig;
import com.rykj.energy.database.service.IUserConfigSercive;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service("userConfigService")
@Slf4j
public class UserConfigServiceImpl extends BaseService<UserConfigMapper, BusinessUserConfig> implements IUserConfigSercive {

    @Autowired
    private UserConfigMapper userConfigMapper;

    @Override
    public void saveOrUpdateUserConfig(BusinessUserConfig entity) {

        if(entity.getId()!=null&&entity.getId()!=0){
            updateUserConfig(entity);
        }else{
            userConfigMapper.insert(entity);
        }
    }

    @Override
    public void updateUserConfig(BusinessUserConfig userConfig) {
        userConfigMapper.updateById(userConfig);
    }

    @Override
    public BusinessUserConfig findUserConfig(Integer userId) {
        Map params = new HashMap<>();
        params.put("userId",userId);
        List<BusinessUserConfig> userConfigList = userConfigMapper.selectByMap(params);
        return userConfigList!=null&&userConfigList.size()>0?userConfigList.get(0):null;
    }
}
